package com.lgy.itcast.haoke.dubbo.api.controller;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.lgy.itcast.haoke.dubbo.api.service.HouseResourcesService;
import com.lgy.itcast.haoke.dubbo.server.beans.HouseResources;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 李光耀
 * @Date 2019-05-28 16:55
 */
@Controller
@RequestMapping("house/resources")
public class HouseResourcesController {

    @Autowired
    private HouseResourcesService houseResourcesService;

    @NacosValue(value = "${nacos.test.propertie:123}", autoRefreshed = true)
    private String testProperties;

    /**
     * 新增房源
     * @param houseResources
     */
    @PostMapping
    @ResponseBody
    public ResponseEntity<Void> save(@RequestBody HouseResources houseResources){
        try {
            boolean bool = this.houseResourcesService.save(houseResources);
            if(bool){
                return ResponseEntity.status(HttpStatus.OK).build();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    @GetMapping
    @ResponseBody
    public ResponseEntity<String> get() {
        return ResponseEntity.ok(testProperties);
    }
}
